/* eslint-disable max-lines */
import * as BASE from '@/stores/definitions-base';
import { t } from '@lingui/macro';
import React from 'react';

const {
  DATETIME_TEXT,
  DATE_TEXT,
  TIME_TEXT,
  EMPTY_TEXT,
  ENUMS: ENUMSBase,
  FieldsGrid: FieldGridBase,
  TitleGrid,
  column: columnBase,
  toSelectDataSource,
} = BASE;
export { DATETIME_TEXT, DATE_TEXT, EMPTY_TEXT, TIME_TEXT, TitleGrid, toSelectDataSource };

/**
 * @param {*} path        属性path
 * @param {*} props       column属性
 * @returns column定义
 */
export function column(...args) {
  return columnBase(themeModal, ...args);
}

/**
 * 显示一组表单字段
 * ```js
 * {
 *   fields: string[],    // 字段名称，可以使用.来指定嵌套对象属性，例如order.busOrder.shift
 *   columns: number,     // 列数，默认为4,最大为12,最小为1
 *   model: object,       // 字段定义数据模型的根对象，默认不指定，仅在使用子对象作为根模型时设置
 *   overrideModel: object, // 重载字段定义数据模型
 *   mode: string,        // 表单模式，默认为edit，可选view
 *   itemLayout: object,  // FormItem布局配置，默认为{}
 * }
 * ```
 *
 * @param {object} param0
 * @returns
 */
export function FieldsGrid(props) {
  return <FieldGridBase model={themeModal} {...props} />;
}

//----------------------------------------------------------------------
export const ENUMS = {
  ...ENUMSBase,
};

/**
 * 模型定义：
 * 1. 普通文本仅需要定义label
 * 2. 需要通过枚举转换的值，定义text; 当使用renderer返回组件时，text属性无效，需要通过组件的renderPreview来指定预览时的绘制方式
 * 3. 通用的ui属性需要定制时，定义ui; 特定模式(view, edit, add)下的ui，添加后缀定义为ui_<mode>，例如：ui_view, ui_edit, ui_add, ui_table
 * 4. ui可配置属性包括:
 *    renderer: 内容渲染函数, Form表单中的原型为：(value: any, formData: any, fieldDefinition: any) => ReactNode; Table Column中的原型为: (value: any, columnIndex: number, rowData: any) => ReactNode;
 *    itemProps: 表单Form.Item的属性，可以是对象，或函数({ isPreview: boolean, mode: string, value: any, formData: any, ...otherDefinitions}) => void;
 *    span: Grid Cell占用的列数, 默认为1
 *
 * 【注】获取接口的model定义后，vscode中通过正则替换：^(\s+)"label": "([^']+)"  ===> $1label: t`$2`
 */
export const themeModal = {
  extras: {
    label: t`主题色配置`,
    appTitle: {
      label: t`标题`,
      value: {
        label: t`标题`,
        ui: {
          itemProps: { required: true },
        },
      },
    },
    scPropagationLanguage: {
      label: t`专线宣传语`,
      value: {
        label: t`宣传语`,
        ui: {
          itemProps: { required: true },
        },
      },
    },
    busPropagationLanguage: {
      label: t`巴士宣传语`,
      value: {
        label: t`宣传语`,
        ui: {
          itemProps: { required: true },
        },
      },
    },
    singleCcPropagationLanguage: {
      label: t`单程包车宣传语`,
      value: {
        label: t`宣传语`,
        ui: {
          itemProps: { required: true },
        },
      },
    },
    pickCcPropagationLanguage: {
      label: t`接送机包车宣传语`,
      value: {
        label: t`宣传语`,
        ui: {
          itemProps: { required: true },
        },
      },
    },
    localCarPropagationLanguage: {
      label: t`本地用车宣传语`,
      value: {
        label: t`宣传语`,
        ui: {
          itemProps: { required: true },
        },
      },
    },
    singleCcSpecialLanguage: {
      label: t`单程包车特殊宣传语`,
      value: {
        label: t`单程包车特殊宣传语`,
        ui: {
          itemProps: { required: true },
        },
      },
    },
    pickCcSpecialLanguage: {
      label: t`接送机特殊宣传语`,
      value: {
        label: t`接送机特殊宣传语`,
        ui: {
          itemProps: { required: true },
        },
      },
    },
    scSpecialLanguage: {
      label: t`专线特殊宣传语`,
      value: {
        label: t`专线特殊宣传语`,
        ui: {
          itemProps: { required: true },
        },
      },
    },
    busSpecialLanguage: {
      label: t`巴士特殊宣传语`,
      value: {
        label: t`巴士特殊宣传语`,
        ui: {
          itemProps: { required: true },
        },
      },
    },
    localCarSpecialLanguage: {
      label: t`本地用车特殊宣传语`,
      value: {
        label: t`本地用车特殊宣传语`,
        ui: {
          itemProps: { required: true },
        },
      },
    },
    stationPropagationLanguage: {
      label: t`拼车始发站-终点站宣传语`,
      value: {
        label: t`拼车始发站-终点站宣传语`,
        ui: {
          itemProps: { required: true },
        },
      },
    },
    rsPlayOrderCautionLanguage: {
      label: t`拼车下单界面注意事项`,
      value: {
        label: t`拼车下单界面注意事项`,
        ui: {
          itemProps: { required: true },
        },
      },
    },
    rsOrderDetailCautionLanguage: {
      label: t`拼车订单详情界面注意事项`,
      value: {
        label: t`拼车订单详情界面注意事项`,
        ui: {
          itemProps: { required: true },
        },
      },
    },
    themeColor: {
      label: t`主题色`,
      value: {
        label: t`主题色`,
        ui: {
          itemProps: { required: true },
        },
      },
    },
  },
};
